#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        int counts = 0;
        /* 前缀和数组 */
        unordered_map<int, int> sumMap;
        sumMap[0] = 1;
        int sum = 0;
        for (int idx = 0; idx < nums.size(); idx++) {
            sum += nums[idx];
            if (sumMap.count(sum - k) == 1) {
                counts = counts + sumMap[sum - k];
            }
            sumMap[sum]++;
        }
        return counts;
    }
};

int main()
{   
    Solution s;
    vector<int> vt{1, -1, 0};
    int k = 0;
    cout << s.subarraySum(vt, k) << endl;
    return 0;
}